from django.db import models
from datetime import datetime

# Create your models here.

class Project(models.Model):
    '''项目
    '''
    name = models.CharField(max_length=100, unique=True, verbose_name="项目名称")
    memo = models.CharField(max_length=100, blank=True, verbose_name="备注")
    add_time = models.DateField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = '项目'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class Server_Group(models.Model):
    '''主机组
    '''
    name = models.CharField(max_length=100, unique=True, verbose_name="主机组")
    project = models.ForeignKey(Project, null=True, on_delete=models.SET_NULL, verbose_name="项目名称")
    memo = models.CharField(max_length=255, blank=True, verbose_name="备注")
    add_time = models.DateField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = '主机组'
        verbose_name_plural = verbose_name
        unique_together = (('name', 'project'),)

    def __str__(self):
        return self.name

class IDC(models.Model):
    '''IDC
    '''
    name = models.CharField(max_length=100, unique=True, verbose_name="IDC名称")
    memo = models.CharField(max_length=100, blank=True, verbose_name="备注")
    add_time = models.DateField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = 'IDC'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class Service_Device(models.Model):
    '''服务器系统信息'''
    service_status = (
        (0, '下线'),
        (1, '在线'),
        (2, '维护'),
        (3, '报废'),
    )

    name = models.CharField(max_length=100, unique=True, verbose_name="主机名称")
    sn = models.CharField(max_length=100, blank=False, verbose_name="序列号")
    public_ip = models.CharField(max_length=100, blank=False, verbose_name="公网IP")
    private_ip = models.CharField(max_length=100, blank=False, verbose_name="内网IP")
    os = models.CharField(max_length=100, blank=True, verbose_name="系统")
    disk = models.CharField(max_length=100, blank=True, verbose_name="磁盘信息")
    cpu = models.CharField(max_length=100, blank=True, verbose_name="cpu信息")
    idc = models.ForeignKey(IDC, max_length=100, null=True, blank=True, on_delete=models.SET_NULL, verbose_name="机房名称")
    status = models.SmallIntegerField(choices=service_status, verbose_name="设备状态", default=1)
    memo = models.CharField(max_length=100, blank=True, verbose_name="备注")
    add_time = models.DateField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = '服务器系统信息'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


